home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / usenet / sources / volume90 / unix / flex_2_3 / part02 < prev    next >
Encoding:
Internet Message Format  |  1990-08-19  |  56.4 KB

  1. Path: abcfd20.larc.nasa.gov!amiga-request
  2. From: amiga-request@abcfd20.larc.nasa.gov (Amiga Sources/Binaries Moderator)
  3. Subject: v90i229: flex 2.3 - fast lexical analyzer generator, Part02/13
  4. Reply-To: loftus@wpllabs.uucp (William P Loftus)
  5. Newsgroups: comp.sources.amiga
  6. Message-ID: <comp.sources.amiga:v90i229@abcfd20.larc.nasa.gov>
  7. Date: 19 Aug 90 22:42:05 GMT
  8. Approved: tadguy@uunet.UU.NET (Tad Guy)
  9. X-Mail-Submissions-To: amiga@uunet.uu.net
  10. X-Post-Discussions-To: comp.sys.amiga
  11.  
  12. Submitted-by: loftus@wpllabs.uucp (William P Loftus)
  13. Posting-number: Volume 90, Issue 229
  14. Archive-name: unix/flex-2.3/part02
  15.  
  16. #!/bin/sh
  17. # This is a shell archive.  Remove anything before this line, then unpack
  18. # it by saving it into a file and typing "sh file".  To overwrite existing
  19. # files, type "sh file -c".  You can also feed this as standard input via
  20. # unshar, or by typing "sh <file", e.g..  If this archive is complete, you
  21. # will see the following message at the end:
  22. #        "End of archive 2 (of 13)."
  23. # Contents:  Changes misc.c parse.y scan.l
  24. # Wrapped by tadguy@abcfd20 on Sun Aug 19 18:41:42 1990
  25. PATH=/bin:/usr/bin:/usr/ucb ; export PATH
  26. if test -f 'Changes' -a "${1}" != "-c" ; then 
  27.   echo shar: Will not clobber existing file \"'Changes'\"
  28. else
  29. echo shar: Extracting \"'Changes'\" \(11046 characters\)
  30. sed "s/^X//" >'Changes' <<'END_OF_FILE'
  31. XChanges between 2.3 (full) release of 28Jun90 and 2.2 (alpha) release:
  32. X
  33. X    User-visible:
  34. X
  35. X    - A lone <<EOF>> rule (that is, one which is not qualified with
  36. X      a list of start conditions) now specifies the EOF action for
  37. X      *all* start conditions which haven't already had <<EOF>> actions
  38. X      given.  To specify an end-of-file action for just the initial
  39. X      state, use <INITIAL><<EOF>>.
  40. X
  41. X    - -d debug output is now contigent on the global yy_flex_debug
  42. X      being set to a non-zero value, which it is by default.
  43. X
  44. X    - A new macro, YY_USER_INIT, is provided for the user to specify
  45. X      initialization action to be taken on the first call to the
  46. X      scanner.  This action is done before the scanner does its
  47. X      own initialization.
  48. X
  49. X    - yy_new_buffer() has been added as an alias for yy_create_buffer()
  50. X
  51. X    - Comments beginning with '#' and extending to the end of the line
  52. X      now work, but have been deprecated (in anticipation of making
  53. X      flex recognize #line directives).
  54. X
  55. X    - The funky restrictions on when semi-colons could follow the
  56. X      YY_NEW_FILE and yyless macros have been removed.  They now
  57. X      behave identically to functions.
  58. X
  59. X    - A bug in the sample redefinition of YY_INPUT in the documentation
  60. X      has been corrected.
  61. X
  62. X    - A bug in the sample simple tokener in the documentation has
  63. X      been corrected.
  64. X
  65. X    - The documentation on the incompatibilities between flex and
  66. X      lex has been reordered so that the discussion of yylineno
  67. X      and input() come first, as it's anticipated that these will
  68. X      be the most common source of headaches.
  69. X
  70. X
  71. X    Things which didn't used to be documented but now are:
  72. X
  73. X    - flex interprets "^foo|bar" differently from lex.  flex interprets
  74. X      it as "match either a 'foo' or a 'bar', providing it comes at the
  75. X      beginning of a line", whereas lex interprets it as "match either
  76. X      a 'foo' at the beginning of a line, or a 'bar' anywhere".
  77. X
  78. X    - flex initializes the global "yyin" on the first call to the
  79. X      scanner, while lex initializes it at compile-time.
  80. X
  81. X    - yy_switch_to_buffer() can be used in the yywrap() macro/routine.
  82. X
  83. X    - flex scanners do not use stdio for their input, and hence when
  84. X      writing an interactive scanner one must explictly call fflush()
  85. X      after writing out a prompt.
  86. X
  87. X    - flex scanner can be made reentrant (after a fashion) by using
  88. X      "yyrestart( yyin );".  This is useful for interactive scanners
  89. X      which have interrupt handlers that long-jump out of the scanner.
  90. X
  91. X    - a defense of why yylineno is not supported is included, along
  92. X      with a suggestion on how to convert scanners which rely on it.
  93. X
  94. X
  95. X    Other changes:
  96. X
  97. X    - Prototypes and proper declarations of void routines have
  98. X      been added to the flex source code, courtesy of Kevin B. Kenny.
  99. X
  100. X    - Routines dealing with memory allocation now use void* pointers
  101. X      instead of char* - see Makefile for porting implications.
  102. X
  103. X    - Error-checking is now done when flex closes a file.
  104. X
  105. X    - Various lint tweaks were added to reduce the number of gripes.
  106. X
  107. X    - Makefile has been further parameterized to aid in porting.
  108. X
  109. X    - Support for SCO Unix added.
  110. X
  111. X    - Flex now sports the latest & greatest UC copyright notice
  112. X      (which is only slightly different from the previous one).
  113. X
  114. X    - A note has been added to flexdoc.1 mentioning work in progress
  115. X      on modifying flex to generate straight C code rather than a
  116. X      table-driven automaton, with an email address of whom to contact
  117. X      if you are working along similar lines.
  118. X
  119. X
  120. XChanges between 2.2 Patch #3 (30Mar90) and 2.2 Patch #2:
  121. X
  122. X    - fixed bug which caused -I scanners to bomb
  123. X
  124. X
  125. XChanges between 2.2 Patch #2 (27Mar90) and 2.2 Patch #1:
  126. X
  127. X    - fixed bug writing past end of input buffer in yyunput()
  128. X    - fixed bug detecting NUL's at the end of a buffer
  129. X
  130. X
  131. XChanges between 2.2 Patch #1 (23Mar90) and 2.2 (alpha) release:
  132. X
  133. X    - Makefile fixes: definition of MAKE variable for systems
  134. X      which don't have it; installation of flexdoc.1 along with
  135. X      flex.1; fixed two bugs which could cause "bigtest" to fail.
  136. X
  137. X    - flex.skel fix for compiling with g++.
  138. X
  139. X    - README and flexdoc.1 no longer list an out-of-date BITNET address
  140. X      for contacting me.
  141. X
  142. X    - minor typos and formatting changes to flex.1 and flexdoc.1.
  143. X
  144. X
  145. XChanges between 2.2 (alpha) release of March '90 and previous release:
  146. X
  147. X    User-visible:
  148. X
  149. X    - Full user documentation now available.
  150. X
  151. X    - Support for 8-bit scanners.
  152. X
  153. X    - Scanners now accept NUL's.
  154. X
  155. X    - A facility has been added for dealing with multiple
  156. X      input buffers.
  157. X
  158. X    - Two manual entries now.  One which fully describes flex
  159. X      (rather than just its differences from lex), and the
  160. X      other for quick(er) reference.
  161. X
  162. X    - A number of changes to bring flex closer into compliance
  163. X      with the latest POSIX lex draft:
  164. X
  165. X        %t support
  166. X        flex now accepts multiple input files and concatenates
  167. X            them together to form its input
  168. X        previous -c (compress) flag renamed -C
  169. X        do-nothing -c and -n flags added
  170. X        Any indented code or code within %{}'s in section 2 is
  171. X            now copied to the output
  172. X
  173. X    - yyleng is now a bona fide global integer.
  174. X
  175. X    - -d debug information now gives the line number of the
  176. X      matched rule instead of which number rule it was from
  177. X      the beginning of the file.
  178. X
  179. X    - -v output now includes a summary of the flags used to generate
  180. X      the scanner.
  181. X
  182. X    - unput() and yyrestart() are now globally callable.
  183. X
  184. X    - yyrestart() no longer closes the previous value of yyin.
  185. X
  186. X    - C++ support; generated scanners can be compiled with C++ compiler.
  187. X
  188. X    - Primitive -lfl library added, containing default main()
  189. X      which calls yylex().  A number of routines currently living
  190. X      in the scanner skeleton will probably migrate to here
  191. X      in the future (in particular, yywrap() will probably cease
  192. X      to be a macro and instead be a function in the -lfl library).
  193. X
  194. X    - Hexadecimal (\x) escape sequences added.
  195. X
  196. X    - Support for MS-DOS, VMS, and Turbo-C integrated.
  197. X
  198. X    - The %used/%unused operators have been deprecated.  They
  199. X      may go away soon.
  200. X
  201. X
  202. X    Other changes:
  203. X
  204. X    - Makefile enhanced for easier testing and installation.
  205. X    - The parser has been tweaked to detect some erroneous
  206. X      constructions which previously were missed.
  207. X    - Scanner input buffer overflow is now detected.
  208. X    - Bugs with missing "const" declarations fixed.
  209. X    - Out-of-date Minix/Atari patches provided.
  210. X    - Scanners no longer require printf() unless FLEX_DEBUG is being used.
  211. X    - A subtle input() bug has been fixed.
  212. X    - Line numbers for "continued action" rules (those following
  213. X      the special '|' action) are now correct.
  214. X    - unput() bug fixed; had been causing problems porting flex to VMS.
  215. X    - yymore() handling rewritten to fix bug with interaction
  216. X      between yymore() and trailing context.
  217. X    - EOF in actions now generates an error message.
  218. X    - Bug involving -CFe and generating equivalence classes fixed.
  219. X    - Bug which made -CF be treated as -Cf fixed.
  220. X    - Support for SysV tmpnam() added.
  221. X    - Unused #define's for scanner no longer generated.
  222. X    - Error messages which are associated with a particular input
  223. X      line are now all identified with their input line in standard
  224. X      format.
  225. X    - % directives which are valid to lex but not to flex are
  226. X      now ignored instead of generating warnings.
  227. X    - -DSYS_V flag can now also be specified -DUSG for System V
  228. X      compilation.
  229. X
  230. X
  231. XChanges between 2.1 beta-test release of June '89 and previous release:
  232. X
  233. X    User-visible:
  234. X
  235. X    - -p flag generates a performance report to stderr.  The report
  236. X      consists of comments regarding features of the scanner rules
  237. X      which result in slower scanners.
  238. X
  239. X    - -b flag generates backtracking information to lex.backtrack.
  240. X      This is a list of scanner states which require backtracking
  241. X      and the characters on which they do so.  By adding rules
  242. X      one can remove backtracking states.  If all backtracking states
  243. X      are eliminated, the generated scanner will run faster.
  244. X      Backtracking is not yet documented in the manual entry.
  245. X
  246. X    - Variable trailing context now works, i.e., one can have
  247. X      rules like "(foo)*/[ \t]*bletch".  Some trailing context
  248. X      patterns still cannot be properly matched and generate
  249. X      error messages.  These are patterns where the ending of the
  250. X      first part of the rule matches the beginning of the second
  251. X      part, such as "zx*/xy*", where the 'x*' matches the 'x' at
  252. X      the beginning of the trailing context.  Lex won't get these
  253. X      patterns right either.
  254. X
  255. X    - Faster scanners.
  256. X
  257. X    - End-of-file rules.  The special rule "<<EOF>>" indicates
  258. X      actions which are to be taken when an end-of-file is
  259. X      encountered and yywrap() returns non-zero (i.e., indicates
  260. X      no further files to process).  See manual entry for example.
  261. X
  262. X    - The -r (reject used) flag is gone.  flex now scans the input
  263. X      for occurrences of the string "REJECT" to determine if the
  264. X      action is needed.  It tries to be intelligent about this but
  265. X      can be fooled.  One can force the presence or absence of
  266. X      REJECT by adding a line in the first section of the form
  267. X      "%used REJECT" or "%unused REJECT".
  268. X
  269. X    - yymore() has been implemented.  Similarly to REJECT, flex
  270. X      detects the use of yymore(), which can be overridden using
  271. X      "%used" or "%unused".
  272. X
  273. X    - Patterns like "x{0,3}" now work (i.e., with lower-limit == 0).
  274. X
  275. X    - Removed '\^x' for ctrl-x misfeature.
  276. X
  277. X    - Added '\a' and '\v' escape sequences.
  278. X
  279. X    - \<digits> now works for octal escape sequences; previously
  280. X      \0<digits> was required.
  281. X
  282. X    - Better error reporting; line numbers are associated with rules.
  283. X
  284. X    - yyleng is a macro; it cannot be accessed outside of the
  285. X      scanner source file.
  286. X
  287. X    - yytext and yyleng should not be modified within a flex action.
  288. X
  289. X    - Generated scanners #define the name FLEX_SCANNER.
  290. X
  291. X    - Rules are internally separated by YY_BREAK in lex.yy.c rather
  292. X      than break, to allow redefinition.
  293. X
  294. X    - The macro YY_USER_ACTION can be redefined to provide an action
  295. X      which is always executed prior to the matched rule's action.
  296. X    
  297. X    - yyrestart() is a new action which can be used to restart
  298. X      the scanner after it has seen an end-of-file (a "real" one,
  299. X      that is, one for which yywrap() returned non-zero).  It takes
  300. X      a FILE* argument indicating a new file to scan and sets
  301. X      things up so that a subsequent call to yylex() will start
  302. X      scanning that file.
  303. X
  304. X    - Internal scanner names all preceded by "yy_"
  305. X
  306. X    - lex.yy.c is deleted if errors are encountered during processing.
  307. X
  308. X    - Comments may be put in the first section of the input by preceding
  309. X      them with '#'.
  310. X
  311. X
  312. X
  313. X    Other changes:
  314. X
  315. X    - Some portability-related bugs fixed, in particular for machines
  316. X      with unsigned characters or sizeof( int* ) != sizeof( int ).
  317. X      Also, tweaks for VMS and Microsoft C (MS-DOS), and identifiers all
  318. X      trimmed to be 31 or fewer characters.  Shortened file names
  319. X      for dinosaur OS's.  Checks for allocating > 64K memory
  320. X      on 16 bit'ers.  Amiga tweaks.  Compiles using gcc on a Sun-3.
  321. X    - Compressed and fast scanner skeletons merged.
  322. X    - Skeleton header files done away with.
  323. X    - Generated scanner uses prototypes and "const" for __STDC__.
  324. X    - -DSV flag is now -DSYS_V for System V compilation.
  325. X    - Removed all references to FTL language.
  326. X    - Software now covered by BSD Copyright.
  327. X    - flex will replace lex in subsequent BSD releases.
  328. END_OF_FILE
  329. if test 11046 -ne `wc -c <'Changes'`; then
  330.     echo shar: \"'Changes'\" unpacked with wrong size!
  331. fi
  332. # end of 'Changes'
  333. fi
  334. if test -f 'misc.c' -a "${1}" != "-c" ; then 
  335.   echo shar: Will not clobber existing file \"'misc.c'\"
  336. else
  337. echo shar: Extracting \"'misc.c'\" \(14248 characters\)
  338. sed "s/^X//" >'misc.c' <<'END_OF_FILE'
  339. X/* misc - miscellaneous flex routines */
  340. X
  341. X/*-
  342. X * Copyright (c) 1990 The Regents of the University of California.
  343. X * All rights reserved.
  344. X *
  345. X * This code is derived from software contributed to Berkeley by
  346. X * Vern Paxson.
  347. X * 
  348. X * The United States Government has rights in this work pursuant
  349. X * to contract no. DE-AC03-76SF00098 between the United States
  350. X * Department of Energy and the University of California.
  351. X *
  352. X * Redistribution and use in source and binary forms are permitted provided
  353. X * that: (1) source distributions retain this entire copyright notice and
  354. X * comment, and (2) distributions including binaries display the following
  355. X * acknowledgement:  ``This product includes software developed by the
  356. X * University of California, Berkeley and its contributors'' in the
  357. X * documentation or other materials provided with the distribution and in
  358. X * all advertising materials mentioning features or use of this software.
  359. X * Neither the name of the University nor the names of its contributors may
  360. X * be used to endorse or promote products derived from this software without
  361. X * specific prior written permission.
  362. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  363. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  364. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  365. X */
  366. X
  367. X#ifndef lint
  368. Xstatic char rcsid[] =
  369. X    "@(#) $Header: WPL:Generators/flex-2.3/RCS/misc.c,v 1.2 90/07/15 01:18:35 loftus Exp $ (LBL)";
  370. X#endif
  371. X
  372. X#include <ctype.h>
  373. X#include "flexdef.h"
  374. X
  375. X
  376. X/* ANSI C does not guarantee that isascii() is defined */
  377. X#ifndef isascii
  378. X#define isascii(c) ((c) <= 0177)
  379. X#endif
  380. X
  381. X
  382. X
  383. X/* declare functions that have forward references */
  384. X
  385. Xvoid dataflush PROTO(());
  386. Xint otoi PROTO((Char []));
  387. X
  388. X
  389. X/* action_out - write the actions from the temporary file to lex.yy.c
  390. X *
  391. X * synopsis
  392. X *     action_out();
  393. X *
  394. X *     Copies the action file up to %% (or end-of-file) to lex.yy.c
  395. X */
  396. X
  397. Xvoid action_out()
  398. X
  399. X    {
  400. X    char buf[MAXLINE];
  401. X
  402. X    while ( fgets( buf, MAXLINE, temp_action_file ) != NULL )
  403. X    if ( buf[0] == '%' && buf[1] == '%' )
  404. X        break;
  405. X    else
  406. X        fputs( buf, stdout );
  407. X    }
  408. X
  409. X
  410. X/* allocate_array - allocate memory for an integer array of the given size */
  411. X
  412. Xvoid *allocate_array( size, element_size )
  413. Xint size, element_size;
  414. X
  415. X    {
  416. X    register void *mem;
  417. X
  418. X    /* on 16-bit int machines (e.g., 80286) we might be trying to
  419. X     * allocate more than a signed int can hold, and that won't
  420. X     * work.  Cheap test:
  421. X     */
  422. X    if ( element_size * size <= 0 )
  423. X        flexfatal( "request for < 1 byte in allocate_array()" );
  424. X
  425. X    mem = (void *) malloc( (unsigned) (element_size * size) );
  426. X
  427. X    if ( mem == NULL )
  428. X    flexfatal( "memory allocation failed in allocate_array()" );
  429. X
  430. X    return ( mem );
  431. X    }
  432. X
  433. X
  434. X/* all_lower - true if a string is all lower-case
  435. X *
  436. X * synopsis:
  437. X *    Char *str;
  438. X *    int all_lower();
  439. X *    true/false = all_lower( str );
  440. X */
  441. X
  442. Xint all_lower( str )
  443. Xregister Char *str;
  444. X
  445. X    {
  446. X    while ( *str )
  447. X    {
  448. X    if ( ! isascii( *str ) || ! islower( *str ) )
  449. X        return ( 0 );
  450. X    ++str;
  451. X    }
  452. X
  453. X    return ( 1 );
  454. X    }
  455. X
  456. X
  457. X/* all_upper - true if a string is all upper-case
  458. X *
  459. X * synopsis:
  460. X *    Char *str;
  461. X *    int all_upper();
  462. X *    true/false = all_upper( str );
  463. X */
  464. X
  465. Xint all_upper( str )
  466. Xregister Char *str;
  467. X
  468. X    {
  469. X    while ( *str )
  470. X    {
  471. X    if ( ! isascii( *str ) || ! isupper( (char) *str ) )
  472. X        return ( 0 );
  473. X    ++str;
  474. X    }
  475. X
  476. X    return ( 1 );
  477. X    }
  478. X
  479. X
  480. X/* bubble - bubble sort an integer array in increasing order
  481. X *
  482. X * synopsis
  483. X *   int v[n], n;
  484. X *   bubble( v, n );
  485. X *
  486. X * description
  487. X *   sorts the first n elements of array v and replaces them in
  488. X *   increasing order.
  489. X *
  490. X * passed
  491. X *   v - the array to be sorted
  492. X *   n - the number of elements of 'v' to be sorted */
  493. X
  494. Xvoid bubble( v, n )
  495. Xint v[], n;
  496. X
  497. X    {
  498. X    register int i, j, k;
  499. X
  500. X    for ( i = n; i > 1; --i )
  501. X    for ( j = 1; j < i; ++j )
  502. X        if ( v[j] > v[j + 1] )    /* compare */
  503. X        {
  504. X        k = v[j];    /* exchange */
  505. X        v[j] = v[j + 1];
  506. X        v[j + 1] = k;
  507. X        }
  508. X    }
  509. X
  510. X
  511. X/* clower - replace upper-case letter to lower-case
  512. X *
  513. X * synopsis:
  514. X *    Char clower();
  515. X *    int c;
  516. X *    c = clower( c );
  517. X */
  518. X
  519. XChar clower( c )
  520. Xregister int c;
  521. X
  522. X    {
  523. X    return ( (isascii( c ) && isupper( c )) ? tolower( c ) : c );
  524. X    }
  525. X
  526. X
  527. X/* copy_string - returns a dynamically allocated copy of a string
  528. X *
  529. X * synopsis
  530. X *    char *str, *copy, *copy_string();
  531. X *    copy = copy_string( str );
  532. X */
  533. X
  534. Xchar *copy_string( str )
  535. Xregister char *str;
  536. X
  537. X    {
  538. X    register char *c;
  539. X    char *copy;
  540. X
  541. X    /* find length */
  542. X    for ( c = str; *c; ++c )
  543. X    ;
  544. X
  545. X    copy = malloc( (unsigned) ((c - str + 1) * sizeof( char )) );
  546. X
  547. X    if ( copy == NULL )
  548. X    flexfatal( "dynamic memory failure in copy_string()" );
  549. X
  550. X    for ( c = copy; (*c++ = *str++); )
  551. X    ;
  552. X
  553. X    return ( copy );
  554. X    }
  555. X
  556. X
  557. X/* copy_unsigned_string -
  558. X *    returns a dynamically allocated copy of a (potentially) unsigned string
  559. X *
  560. X * synopsis
  561. X *    Char *str, *copy, *copy_unsigned_string();
  562. X *    copy = copy_unsigned_string( str );
  563. X */
  564. X
  565. XChar *copy_unsigned_string( str )
  566. Xregister Char *str;
  567. X
  568. X    {
  569. X    register Char *c;
  570. X    Char *copy;
  571. X
  572. X    /* find length */
  573. X    for ( c = str; *c; ++c )
  574. X    ;
  575. X
  576. X    copy = (Char *) malloc( (unsigned) ((c - str + 1) * sizeof( Char )) );
  577. X
  578. X    if ( copy == NULL )
  579. X    flexfatal( "dynamic memory failure in copy_unsigned_string()" );
  580. X
  581. X    for ( c = copy; (*c++ = *str++); )
  582. X    ;
  583. X
  584. X    return ( copy );
  585. X    }
  586. X
  587. X
  588. X/* cshell - shell sort a character array in increasing order
  589. X *
  590. X * synopsis
  591. X *
  592. X *   Char v[n];
  593. X *   int n, special_case_0;
  594. X *   cshell( v, n, special_case_0 );
  595. X *
  596. X * description
  597. X *   does a shell sort of the first n elements of array v.
  598. X *   If special_case_0 is true, then any element equal to 0
  599. X *   is instead assumed to have infinite weight.
  600. X *
  601. X * passed
  602. X *   v - array to be sorted
  603. X *   n - number of elements of v to be sorted
  604. X */
  605. X
  606. Xvoid cshell( v, n, special_case_0 )
  607. XChar v[];
  608. Xint n, special_case_0;
  609. X
  610. X    {
  611. X    int gap, i, j, jg;
  612. X    Char k;
  613. X
  614. X    for ( gap = n / 2; gap > 0; gap = gap / 2 )
  615. X    for ( i = gap; i < n; ++i )
  616. X        for ( j = i - gap; j >= 0; j = j - gap )
  617. X        {
  618. X        jg = j + gap;
  619. X
  620. X        if ( special_case_0 )
  621. X            {
  622. X            if ( v[jg] == 0 )
  623. X            break;
  624. X
  625. X            else if ( v[j] != 0 && v[j] <= v[jg] )
  626. X            break;
  627. X            }
  628. X
  629. X        else if ( v[j] <= v[jg] )
  630. X            break;
  631. X
  632. X        k = v[j];
  633. X        v[j] = v[jg];
  634. X        v[jg] = k;
  635. X        }
  636. X    }
  637. X
  638. X
  639. X/* dataend - finish up a block of data declarations
  640. X *
  641. X * synopsis
  642. X *    dataend();
  643. X */
  644. X
  645. Xvoid dataend()
  646. X
  647. X    {
  648. X    if ( datapos > 0 )
  649. X    dataflush();
  650. X
  651. X    /* add terminator for initialization */
  652. X    puts( "    } ;\n" );
  653. X
  654. X    dataline = 0;
  655. X    datapos = 0;
  656. X    }
  657. X
  658. X
  659. X
  660. X/* dataflush - flush generated data statements
  661. X *
  662. X * synopsis
  663. X *    dataflush();
  664. X */
  665. X
  666. Xvoid dataflush()
  667. X
  668. X    {
  669. X    putchar( '\n' );
  670. X
  671. X    if ( ++dataline >= NUMDATALINES )
  672. X    {
  673. X    /* put out a blank line so that the table is grouped into
  674. X     * large blocks that enable the user to find elements easily
  675. X     */
  676. X    putchar( '\n' );
  677. X    dataline = 0;
  678. X    }
  679. X
  680. X    /* reset the number of characters written on the current line */
  681. X    datapos = 0;
  682. X    }
  683. X
  684. X
  685. X/* flexerror - report an error message and terminate
  686. X *
  687. X * synopsis
  688. X *    char msg[];
  689. X *    flexerror( msg );
  690. X */
  691. X
  692. Xvoid flexerror( msg )
  693. Xchar msg[];
  694. X
  695. X    {
  696. X    fprintf( stderr, "%s: %s\n", program_name, msg );
  697. X
  698. X    flexend( 1 );
  699. X    }
  700. X
  701. X
  702. X/* flexfatal - report a fatal error message and terminate
  703. X *
  704. X * synopsis
  705. X *    char msg[];
  706. X *    flexfatal( msg );
  707. X */
  708. X
  709. Xvoid flexfatal( msg )
  710. Xchar msg[];
  711. X
  712. X    {
  713. X    fprintf( stderr, "%s: fatal internal error, %s\n", program_name, msg );
  714. X    flexend( 1 );
  715. X    }
  716. X
  717. X
  718. X/* flex_gettime - return current time
  719. X *
  720. X * synopsis
  721. X *    char *flex_gettime(), *time_str;
  722. X *    time_str = flex_gettime();
  723. X *
  724. X * note
  725. X *    the routine name has the "flex_" prefix because of name clashes
  726. X *    with Turbo-C
  727. X */
  728. X
  729. X/* include sys/types.h to use time_t and make lint happy */
  730. X
  731. X#ifndef MS_DOS
  732. X#ifndef VMS
  733. X#include <sys/types.h>
  734. X#else
  735. X#include <types.h>
  736. X#endif
  737. X#endif
  738. X
  739. X#ifdef MS_DOS
  740. X#include <time.h>
  741. Xtypedef long time_t;
  742. X#endif
  743. X
  744. X#ifdef AMIGA
  745. X#include <time.h>
  746. X#endif
  747. X
  748. Xchar *flex_gettime()
  749. X
  750. X    {
  751. X    time_t t, time();
  752. X    char *result, *ctime(), *copy_string();
  753. X
  754. X    t = time( (long *) 0 );
  755. X
  756. X    result = copy_string( ctime( &t ) );
  757. X
  758. X    /* get rid of trailing newline */
  759. X    result[24] = '\0';
  760. X
  761. X    return ( result );
  762. X    }
  763. X
  764. X
  765. X/* lerrif - report an error message formatted with one integer argument
  766. X *
  767. X * synopsis
  768. X *    char msg[];
  769. X *    int arg;
  770. X *    lerrif( msg, arg );
  771. X */
  772. X
  773. Xvoid lerrif( msg, arg )
  774. Xchar msg[];
  775. Xint arg;
  776. X
  777. X    {
  778. X    char errmsg[MAXLINE];
  779. X    (void) sprintf( errmsg, msg, arg );
  780. X    flexerror( errmsg );
  781. X    }
  782. X
  783. X
  784. X/* lerrsf - report an error message formatted with one string argument
  785. X *
  786. X * synopsis
  787. X *    char msg[], arg[];
  788. X *    lerrsf( msg, arg );
  789. X */
  790. X
  791. Xvoid lerrsf( msg, arg )
  792. Xchar msg[], arg[];
  793. X
  794. X    {
  795. X    char errmsg[MAXLINE];
  796. X
  797. X    (void) sprintf( errmsg, msg, arg );
  798. X    flexerror( errmsg );
  799. X    }
  800. X
  801. X
  802. X/* htoi - convert a hexadecimal digit string to an integer value
  803. X *
  804. X * synopsis:
  805. X *    int val, htoi();
  806. X *    Char str[];
  807. X *    val = htoi( str );
  808. X */
  809. X
  810. Xint htoi( str )
  811. XChar str[];
  812. X
  813. X    {
  814. X    int result;
  815. X
  816. X    (void) sscanf( (char *) str, "%x", &result );
  817. X
  818. X    return ( result );
  819. X    }
  820. X
  821. X
  822. X/* line_directive_out - spit out a "# line" statement */
  823. X
  824. Xvoid line_directive_out( output_file_name )
  825. XFILE *output_file_name;
  826. X
  827. X    {
  828. X    if ( infilename && gen_line_dirs )
  829. X        fprintf( output_file_name, "# line %d \"%s\"\n", linenum, infilename );
  830. X    }
  831. X
  832. X
  833. X/* mk2data - generate a data statement for a two-dimensional array
  834. X *
  835. X * synopsis
  836. X *    int value;
  837. X *    mk2data( value );
  838. X *
  839. X *  generates a data statement initializing the current 2-D array to "value"
  840. X */
  841. Xvoid mk2data( value )
  842. Xint value;
  843. X
  844. X    {
  845. X    if ( datapos >= NUMDATAITEMS )
  846. X    {
  847. X    putchar( ',' );
  848. X    dataflush();
  849. X    }
  850. X
  851. X    if ( datapos == 0 )
  852. X    /* indent */
  853. X    fputs( "    ", stdout );
  854. X
  855. X    else
  856. X    putchar( ',' );
  857. X
  858. X    ++datapos;
  859. X
  860. X    printf( "%5d", value );
  861. X    }
  862. X
  863. X
  864. X/* mkdata - generate a data statement
  865. X *
  866. X * synopsis
  867. X *    int value;
  868. X *    mkdata( value );
  869. X *
  870. X *  generates a data statement initializing the current array element to
  871. X *  "value"
  872. X */
  873. Xvoid mkdata( value )
  874. Xint value;
  875. X
  876. X    {
  877. X    if ( datapos >= NUMDATAITEMS )
  878. X    {
  879. X    putchar( ',' );
  880. X    dataflush();
  881. X    }
  882. X
  883. X    if ( datapos == 0 )
  884. X    /* indent */
  885. X    fputs( "    ", stdout );
  886. X
  887. X    else
  888. X    putchar( ',' );
  889. X
  890. X    ++datapos;
  891. X
  892. X    printf( "%5d", value );
  893. X    }
  894. X
  895. X
  896. X/* myctoi - return the integer represented by a string of digits
  897. X *
  898. X * synopsis
  899. X *    Char array[];
  900. X *    int val, myctoi();
  901. X *    val = myctoi( array );
  902. X *
  903. X */
  904. X
  905. Xint myctoi( array )
  906. XChar array[];
  907. X
  908. X    {
  909. X    int val = 0;
  910. X
  911. X    (void) sscanf( (char *) array, "%d", &val );
  912. X
  913. X    return ( val );
  914. X    }
  915. X
  916. X
  917. X/* myesc - return character corresponding to escape sequence
  918. X *
  919. X * synopsis
  920. X *    Char array[], c, myesc();
  921. X *    c = myesc( array );
  922. X *
  923. X */
  924. X
  925. XChar myesc( array )
  926. XChar array[];
  927. X
  928. X    {
  929. X    switch ( array[1] )
  930. X    {
  931. X    case 'a': return ( '\a' );
  932. X    case 'b': return ( '\b' );
  933. X    case 'f': return ( '\f' );
  934. X    case 'n': return ( '\n' );
  935. X    case 'r': return ( '\r' );
  936. X    case 't': return ( '\t' );
  937. X    case 'v': return ( '\v' );
  938. X
  939. X    case 'x':
  940. X        /* fall through */
  941. X
  942. X    case '0':
  943. X    case '1':
  944. X    case '2':
  945. X    case '3':
  946. X    case '4':
  947. X    case '5':
  948. X    case '6':
  949. X    case '7':
  950. X    case '8':
  951. X    case '9':
  952. X
  953. X        { /* \<octal> or \x<hex> */
  954. X        Char c, esc_char;
  955. X        register int sptr = 1;
  956. X
  957. X        if ( array[1] == 'x' )
  958. X        ++sptr;
  959. X
  960. X        while ( isascii( array[sptr] ) && isdigit( array[sptr] ) )
  961. X        /* don't increment inside loop control because if
  962. X         * isdigit() is a macro it will expand it to two
  963. X         * increments ...
  964. X         */
  965. X        ++sptr;
  966. X
  967. X        c = array[sptr];
  968. X        array[sptr] = '\0';
  969. X
  970. X        if ( array[1] == 'x' )
  971. X        esc_char = htoi( array + 2 );
  972. X        else
  973. X        esc_char = otoi( array + 1 );
  974. X
  975. X        array[sptr] = c;
  976. X
  977. X        return ( esc_char );
  978. X        }
  979. X
  980. X    default:
  981. X        return ( array[1] );
  982. X    }
  983. X    }
  984. X
  985. X
  986. X/* otoi - convert an octal digit string to an integer value
  987. X *
  988. X * synopsis:
  989. X *    int val, otoi();
  990. X *    Char str[];
  991. X *    val = otoi( str );
  992. X */
  993. X
  994. Xint otoi( str )
  995. XChar str[];
  996. X
  997. X    {
  998. X    int result;
  999. X
  1000. X    (void) sscanf( (char *) str, "%o", &result );
  1001. X
  1002. X    return ( result );
  1003. X    }
  1004. X
  1005. X
  1006. X/* readable_form - return the the human-readable form of a character
  1007. X *
  1008. X * synopsis:
  1009. X *    int c;
  1010. X *    char *readable_form();
  1011. X *    <string> = readable_form( c );
  1012. X *
  1013. X * The returned string is in static storage.
  1014. X */
  1015. X
  1016. Xchar *readable_form( c )
  1017. Xregister int c;
  1018. X
  1019. X    {
  1020. X    static char rform[10];
  1021. X
  1022. X    if ( (c >= 0 && c < 32) || c >= 127 )
  1023. X    {
  1024. X    switch ( c )
  1025. X        {
  1026. X        case '\n': return ( "\\n" );
  1027. X        case '\t': return ( "\\t" );
  1028. X        case '\f': return ( "\\f" );
  1029. X        case '\r': return ( "\\r" );
  1030. X        case '\b': return ( "\\b" );
  1031. X
  1032. X        default:
  1033. X        (void) sprintf( rform, "\\%.3o", c );
  1034. X        return ( rform );
  1035. X        }
  1036. X    }
  1037. X
  1038. X    else if ( c == ' ' )
  1039. X    return ( "' '" );
  1040. X
  1041. X    else
  1042. X    {
  1043. X    rform[0] = c;
  1044. X    rform[1] = '\0';
  1045. X
  1046. X    return ( rform );
  1047. X    }
  1048. X    }
  1049. X
  1050. X
  1051. X/* reallocate_array - increase the size of a dynamic array */
  1052. X
  1053. Xvoid *reallocate_array( array, size, element_size )
  1054. Xvoid *array;
  1055. Xint size, element_size;
  1056. X
  1057. X    {
  1058. X    register void *new_array;
  1059. X
  1060. X    /* same worry as in allocate_array(): */
  1061. X    if ( size * element_size <= 0 )
  1062. X        flexfatal( "attempt to increase array size by less than 1 byte" );
  1063. X
  1064. X    new_array =
  1065. X    (void *) realloc( (char *)array, (unsigned) (size * element_size ));
  1066. X
  1067. X    if ( new_array == NULL )
  1068. X    flexfatal( "attempt to increase array size failed" );
  1069. X
  1070. X    return ( new_array );
  1071. X    }
  1072. X
  1073. X
  1074. X/* skelout - write out one section of the skeleton file
  1075. X *
  1076. X * synopsis
  1077. X *    skelout();
  1078. X *
  1079. X * DESCRIPTION
  1080. X *    Copies from skelfile to stdout until a line beginning with "%%" or
  1081. X *    EOF is found.
  1082. X */
  1083. Xvoid skelout()
  1084. X
  1085. X    {
  1086. X    char buf[MAXLINE];
  1087. X
  1088. X    while ( fgets( buf, MAXLINE, skelfile ) != NULL )
  1089. X    if ( buf[0] == '%' && buf[1] == '%' )
  1090. X        break;
  1091. X    else
  1092. X        fputs( buf, stdout );
  1093. X    }
  1094. X
  1095. X
  1096. X/* transition_struct_out - output a yy_trans_info structure
  1097. X *
  1098. X * synopsis
  1099. X *     int element_v, element_n;
  1100. X *     transition_struct_out( element_v, element_n );
  1101. X *
  1102. X * outputs the yy_trans_info structure with the two elements, element_v and
  1103. X * element_n.  Formats the output with spaces and carriage returns.
  1104. X */
  1105. X
  1106. Xvoid transition_struct_out( element_v, element_n )
  1107. Xint element_v, element_n;
  1108. X
  1109. X    {
  1110. X    printf( "%7d, %5d,", element_v, element_n );
  1111. X
  1112. X    datapos += TRANS_STRUCT_PRINT_LENGTH;
  1113. X
  1114. X    if ( datapos >= 75 )
  1115. X    {
  1116. X    putchar( '\n' );
  1117. X
  1118. X    if ( ++dataline % 10 == 0 )
  1119. X        putchar( '\n' );
  1120. X
  1121. X    datapos = 0;
  1122. X    }
  1123. X    }
  1124. END_OF_FILE
  1125. if test 14248 -ne `wc -c <'misc.c'`; then
  1126.     echo shar: \"'misc.c'\" unpacked with wrong size!
  1127. fi
  1128. # end of 'misc.c'
  1129. fi
  1130. if test -f 'parse.y' -a "${1}" != "-c" ; then 
  1131.   echo shar: Will not clobber existing file \"'parse.y'\"
  1132. else
  1133. echo shar: Extracting \"'parse.y'\" \(14546 characters\)
  1134. sed "s/^X//" >'parse.y' <<'END_OF_FILE'
  1135. X
  1136. X/* parse.y - parser for flex input */
  1137. X
  1138. X%token CHAR NUMBER SECTEND SCDECL XSCDECL WHITESPACE NAME PREVCCL EOF_OP
  1139. X
  1140. X%{
  1141. X/*-
  1142. X * Copyright (c) 1990 The Regents of the University of California.
  1143. X * All rights reserved.
  1144. X *
  1145. X * This code is derived from software contributed to Berkeley by
  1146. X * Vern Paxson.
  1147. X * 
  1148. X * The United States Government has rights in this work pursuant
  1149. X * to contract no. DE-AC03-76SF00098 between the United States
  1150. X * Department of Energy and the University of California.
  1151. X *
  1152. X * Redistribution and use in source and binary forms are permitted provided
  1153. X * that: (1) source distributions retain this entire copyright notice and
  1154. X * comment, and (2) distributions including binaries display the following
  1155. X * acknowledgement:  ``This product includes software developed by the
  1156. X * University of California, Berkeley and its contributors'' in the
  1157. X * documentation or other materials provided with the distribution and in
  1158. X * all advertising materials mentioning features or use of this software.
  1159. X * Neither the name of the University nor the names of its contributors may
  1160. X * be used to endorse or promote products derived from this software without
  1161. X * specific prior written permission.
  1162. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1163. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1164. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1165. X */
  1166. X
  1167. X#ifndef lint
  1168. Xstatic char rcsid[] =
  1169. X    "@(#) $Header: WPL:Generators/flex-2.3/RCS/parse.y,v 1.2 90/07/15 01:16:53 loftus Exp $ (LBL)";
  1170. X#endif
  1171. X
  1172. X#include "flexdef.h"
  1173. X
  1174. Xint pat, scnum, eps, headcnt, trailcnt, anyccl, lastchar, i, actvp, rulelen;
  1175. Xint trlcontxt, xcluflg, cclsorted, varlength, variable_trail_rule;
  1176. XChar clower();
  1177. Xvoid build_eof_action();
  1178. Xvoid yyerror( char * );
  1179. X
  1180. Xstatic int madeany = false;  /* whether we've made the '.' character class */
  1181. Xint previous_continued_action;    /* whether the previous rule's action was '|' */
  1182. X
  1183. X%}
  1184. X
  1185. X%%
  1186. Xgoal            :  initlex sect1 sect1end sect2 initforrule
  1187. X            { /* add default rule */
  1188. X            int def_rule;
  1189. X
  1190. X            pat = cclinit();
  1191. X            cclnegate( pat );
  1192. X
  1193. X            def_rule = mkstate( -pat );
  1194. X
  1195. X            finish_rule( def_rule, false, 0, 0 );
  1196. X
  1197. X            for ( i = 1; i <= lastsc; ++i )
  1198. X                scset[i] = mkbranch( scset[i], def_rule );
  1199. X
  1200. X            if ( spprdflt )
  1201. X                fputs( "YY_FATAL_ERROR( \"flex scanner jammed\" )",
  1202. X                   temp_action_file );
  1203. X            else
  1204. X                fputs( "ECHO", temp_action_file );
  1205. X
  1206. X            fputs( ";\n\tYY_BREAK\n", temp_action_file );
  1207. X            }
  1208. X        ;
  1209. X
  1210. Xinitlex         :
  1211. X            {
  1212. X            /* initialize for processing rules */
  1213. X
  1214. X            /* create default DFA start condition */
  1215. X            scinstal( "INITIAL", false );
  1216. X            }
  1217. X        ;
  1218. X
  1219. Xsect1        :  sect1 startconddecl WHITESPACE namelist1 '\n'
  1220. X        |
  1221. X        |  error '\n'
  1222. X            { synerr( "unknown error processing section 1" ); }
  1223. X        ;
  1224. X
  1225. Xsect1end    :  SECTEND
  1226. X        ;
  1227. X
  1228. Xstartconddecl   :  SCDECL
  1229. X            {
  1230. X            /* these productions are separate from the s1object
  1231. X             * rule because the semantics must be done before
  1232. X             * we parse the remainder of an s1object
  1233. X             */
  1234. X
  1235. X            xcluflg = false;
  1236. X            }
  1237. X
  1238. X        |  XSCDECL
  1239. X            { xcluflg = true; }
  1240. X        ;
  1241. X
  1242. Xnamelist1    :  namelist1 WHITESPACE NAME
  1243. X            { scinstal( nmstr, xcluflg ); }
  1244. X
  1245. X        |  NAME
  1246. X            { scinstal( nmstr, xcluflg ); }
  1247. X
  1248. X        |  error
  1249. X                        { synerr( "bad start condition list" ); }
  1250. X        ;
  1251. X
  1252. Xsect2           :  sect2 initforrule flexrule '\n'
  1253. X        |
  1254. X        ;
  1255. X
  1256. Xinitforrule     :
  1257. X            {
  1258. X            /* initialize for a parse of one rule */
  1259. X            trlcontxt = variable_trail_rule = varlength = false;
  1260. X            trailcnt = headcnt = rulelen = 0;
  1261. X            current_state_type = STATE_NORMAL;
  1262. X            previous_continued_action = continued_action;
  1263. X            new_rule();
  1264. X            }
  1265. X        ;
  1266. X
  1267. Xflexrule        :  scon '^' rule
  1268. X                        {
  1269. X            pat = $3;
  1270. X            finish_rule( pat, variable_trail_rule,
  1271. X                     headcnt, trailcnt );
  1272. X
  1273. X            for ( i = 1; i <= actvp; ++i )
  1274. X                scbol[actvsc[i]] =
  1275. X                mkbranch( scbol[actvsc[i]], pat );
  1276. X
  1277. X            if ( ! bol_needed )
  1278. X                {
  1279. X                bol_needed = true;
  1280. X
  1281. X                if ( performance_report )
  1282. X                pinpoint_message( 
  1283. X                "'^' operator results in sub-optimal performance" );
  1284. X                }
  1285. X            }
  1286. X
  1287. X        |  scon rule
  1288. X                        {
  1289. X            pat = $2;
  1290. X            finish_rule( pat, variable_trail_rule,
  1291. X                     headcnt, trailcnt );
  1292. X
  1293. X            for ( i = 1; i <= actvp; ++i )
  1294. X                scset[actvsc[i]] =
  1295. X                mkbranch( scset[actvsc[i]], pat );
  1296. X            }
  1297. X
  1298. X                |  '^' rule
  1299. X            {
  1300. X            pat = $2;
  1301. X            finish_rule( pat, variable_trail_rule,
  1302. X                     headcnt, trailcnt );
  1303. X
  1304. X            /* add to all non-exclusive start conditions,
  1305. X             * including the default (0) start condition
  1306. X             */
  1307. X
  1308. X            for ( i = 1; i <= lastsc; ++i )
  1309. X                if ( ! scxclu[i] )
  1310. X                scbol[i] = mkbranch( scbol[i], pat );
  1311. X
  1312. X            if ( ! bol_needed )
  1313. X                {
  1314. X                bol_needed = true;
  1315. X
  1316. X                if ( performance_report )
  1317. X                pinpoint_message(
  1318. X                "'^' operator results in sub-optimal performance" );
  1319. X                }
  1320. X            }
  1321. X
  1322. X                |  rule
  1323. X            {
  1324. X            pat = $1;
  1325. X            finish_rule( pat, variable_trail_rule,
  1326. X                     headcnt, trailcnt );
  1327. X
  1328. X            for ( i = 1; i <= lastsc; ++i )
  1329. X                if ( ! scxclu[i] )
  1330. X                scset[i] = mkbranch( scset[i], pat );
  1331. X            }
  1332. X
  1333. X                |  scon EOF_OP
  1334. X            { build_eof_action(); }
  1335. X
  1336. X                |  EOF_OP
  1337. X            {
  1338. X            /* this EOF applies to all start conditions
  1339. X             * which don't already have EOF actions
  1340. X             */
  1341. X            actvp = 0;
  1342. X
  1343. X            for ( i = 1; i <= lastsc; ++i )
  1344. X                if ( ! sceof[i] )
  1345. X                actvsc[++actvp] = i;
  1346. X
  1347. X            if ( actvp == 0 )
  1348. X                pinpoint_message(
  1349. X        "warning - all start conditions already have <<EOF>> rules" );
  1350. X
  1351. X            else
  1352. X                build_eof_action();
  1353. X            }
  1354. X
  1355. X                |  error
  1356. X            { synerr( "unrecognized rule" ); }
  1357. X        ;
  1358. X
  1359. Xscon            :  '<' namelist2 '>'
  1360. X        ;
  1361. X
  1362. Xnamelist2       :  namelist2 ',' NAME
  1363. X                        {
  1364. X            if ( (scnum = sclookup( nmstr )) == 0 )
  1365. X                format_pinpoint_message(
  1366. X                "undeclared start condition %s", nmstr );
  1367. X
  1368. X            else
  1369. X                actvsc[++actvp] = scnum;
  1370. X            }
  1371. X
  1372. X        |  NAME
  1373. X            {
  1374. X            if ( (scnum = sclookup( nmstr )) == 0 )
  1375. X                format_pinpoint_message(
  1376. X                "undeclared start condition %s", nmstr );
  1377. X            else
  1378. X                actvsc[actvp = 1] = scnum;
  1379. X            }
  1380. X
  1381. X        |  error
  1382. X            { synerr( "bad start condition list" ); }
  1383. X        ;
  1384. X
  1385. Xrule            :  re2 re
  1386. X            {
  1387. X            if ( transchar[lastst[$2]] != SYM_EPSILON )
  1388. X                /* provide final transition \now/ so it
  1389. X                 * will be marked as a trailing context
  1390. X                 * state
  1391. X                 */
  1392. X                $2 = link_machines( $2, mkstate( SYM_EPSILON ) );
  1393. X
  1394. X            mark_beginning_as_normal( $2 );
  1395. X            current_state_type = STATE_NORMAL;
  1396. X
  1397. X            if ( previous_continued_action )
  1398. X                {
  1399. X                /* we need to treat this as variable trailing
  1400. X                 * context so that the backup does not happen
  1401. X                 * in the action but before the action switch
  1402. X                 * statement.  If the backup happens in the
  1403. X                 * action, then the rules "falling into" this
  1404. X                 * one's action will *also* do the backup,
  1405. X                 * erroneously.
  1406. X                 */
  1407. X                if ( ! varlength || headcnt != 0 )
  1408. X                {
  1409. X                fprintf( stderr,
  1410. X    "%s: warning - trailing context rule at line %d made variable because\n",
  1411. X                     program_name, linenum );
  1412. X                fprintf( stderr,
  1413. X                     "      of preceding '|' action\n" );
  1414. X                }
  1415. X
  1416. X                /* mark as variable */
  1417. X                varlength = true;
  1418. X                headcnt = 0;
  1419. X                }
  1420. X
  1421. X            if ( varlength && headcnt == 0 )
  1422. X                { /* variable trailing context rule */
  1423. X                /* mark the first part of the rule as the accepting
  1424. X                 * "head" part of a trailing context rule
  1425. X                 */
  1426. X                /* by the way, we didn't do this at the beginning
  1427. X                 * of this production because back then
  1428. X                 * current_state_type was set up for a trail
  1429. X                 * rule, and add_accept() can create a new
  1430. X                 * state ...
  1431. X                 */
  1432. X                add_accept( $1, num_rules | YY_TRAILING_HEAD_MASK );
  1433. X                variable_trail_rule = true;
  1434. X                }
  1435. X            
  1436. X            else
  1437. X                trailcnt = rulelen;
  1438. X
  1439. X            $$ = link_machines( $1, $2 );
  1440. X            }
  1441. X
  1442. X        |  re2 re '$'
  1443. X            { synerr( "trailing context used twice" ); }
  1444. X
  1445. X        |  re '$'
  1446. X                        {
  1447. X            if ( trlcontxt )
  1448. X                {
  1449. X                synerr( "trailing context used twice" );
  1450. X                $$ = mkstate( SYM_EPSILON );
  1451. X                }
  1452. X
  1453. X            else if ( previous_continued_action )
  1454. X                {
  1455. X                /* see the comment in the rule for "re2 re"
  1456. X                 * above
  1457. X                 */
  1458. X                if ( ! varlength || headcnt != 0 )
  1459. X                {
  1460. X                fprintf( stderr,
  1461. X    "%s: warning - trailing context rule at line %d made variable because\n",
  1462. X                     program_name, linenum );
  1463. X                fprintf( stderr,
  1464. X                     "      of preceding '|' action\n" );
  1465. X                }
  1466. X
  1467. X                /* mark as variable */
  1468. X                varlength = true;
  1469. X                headcnt = 0;
  1470. X                }
  1471. X
  1472. X            trlcontxt = true;
  1473. X
  1474. X            if ( ! varlength )
  1475. X                headcnt = rulelen;
  1476. X
  1477. X            ++rulelen;
  1478. X            trailcnt = 1;
  1479. X
  1480. X            eps = mkstate( SYM_EPSILON );
  1481. X            $$ = link_machines( $1,
  1482. X                 link_machines( eps, mkstate( '\n' ) ) );
  1483. X            }
  1484. X
  1485. X        |  re
  1486. X            {
  1487. X                $$ = $1;
  1488. X
  1489. X            if ( trlcontxt )
  1490. X                {
  1491. X                if ( varlength && headcnt == 0 )
  1492. X                /* both head and trail are variable-length */
  1493. X                variable_trail_rule = true;
  1494. X                else
  1495. X                trailcnt = rulelen;
  1496. X                }
  1497. X                }
  1498. X        ;
  1499. X
  1500. X
  1501. Xre              :  re '|' series
  1502. X                        {
  1503. X            varlength = true;
  1504. X            $$ = mkor( $1, $3 );
  1505. X            }
  1506. X
  1507. X        |  series
  1508. X            { $$ = $1; }
  1509. X        ;
  1510. X
  1511. X
  1512. Xre2        :  re '/'
  1513. X            {
  1514. X            /* this rule is written separately so
  1515. X             * the reduction will occur before the trailing
  1516. X             * series is parsed
  1517. X             */
  1518. X
  1519. X            if ( trlcontxt )
  1520. X                synerr( "trailing context used twice" );
  1521. X            else
  1522. X                trlcontxt = true;
  1523. X
  1524. X            if ( varlength )
  1525. X                /* we hope the trailing context is fixed-length */
  1526. X                varlength = false;
  1527. X            else
  1528. X                headcnt = rulelen;
  1529. X
  1530. X            rulelen = 0;
  1531. X
  1532. X            current_state_type = STATE_TRAILING_CONTEXT;
  1533. X            $$ = $1;
  1534. X            }
  1535. X        ;
  1536. X
  1537. Xseries          :  series singleton
  1538. X                        {
  1539. X            /* this is where concatenation of adjacent patterns
  1540. X             * gets done
  1541. X             */
  1542. X            $$ = link_machines( $1, $2 );
  1543. X            }
  1544. X
  1545. X        |  singleton
  1546. X            { $$ = $1; }
  1547. X        ;
  1548. X
  1549. Xsingleton       :  singleton '*'
  1550. X                        {
  1551. X            varlength = true;
  1552. X
  1553. X            $$ = mkclos( $1 );
  1554. X            }
  1555. X
  1556. X        |  singleton '+'
  1557. X            {
  1558. X            varlength = true;
  1559. X
  1560. X            $$ = mkposcl( $1 );
  1561. X            }
  1562. X
  1563. X        |  singleton '?'
  1564. X            {
  1565. X            varlength = true;
  1566. X
  1567. X            $$ = mkopt( $1 );
  1568. X            }
  1569. X
  1570. X        |  singleton '{' NUMBER ',' NUMBER '}'
  1571. X            {
  1572. X            varlength = true;
  1573. X
  1574. X            if ( $3 > $5 || $3 < 0 )
  1575. X                {
  1576. X                synerr( "bad iteration values" );
  1577. X                $$ = $1;
  1578. X                }
  1579. X            else
  1580. X                {
  1581. X                if ( $3 == 0 )
  1582. X                $$ = mkopt( mkrep( $1, $3, $5 ) );
  1583. X                else
  1584. X                $$ = mkrep( $1, $3, $5 );
  1585. X                }
  1586. X            }
  1587. X
  1588. X        |  singleton '{' NUMBER ',' '}'
  1589. X            {
  1590. X            varlength = true;
  1591. X
  1592. X            if ( $3 <= 0 )
  1593. X                {
  1594. X                synerr( "iteration value must be positive" );
  1595. X                $$ = $1;
  1596. X                }
  1597. X
  1598. X            else
  1599. X                $$ = mkrep( $1, $3, INFINITY );
  1600. X            }
  1601. X
  1602. X        |  singleton '{' NUMBER '}'
  1603. X            {
  1604. X            /* the singleton could be something like "(foo)",
  1605. X             * in which case we have no idea what its length
  1606. X             * is, so we punt here.
  1607. X             */
  1608. X            varlength = true;
  1609. X
  1610. X            if ( $3 <= 0 )
  1611. X                {
  1612. X                synerr( "iteration value must be positive" );
  1613. X                $$ = $1;
  1614. X                }
  1615. X
  1616. X            else
  1617. X                $$ = link_machines( $1, copysingl( $1, $3 - 1 ) );
  1618. X            }
  1619. X
  1620. X        |  '.'
  1621. X            {
  1622. X            if ( ! madeany )
  1623. X                {
  1624. X                /* create the '.' character class */
  1625. X                anyccl = cclinit();
  1626. X                ccladd( anyccl, '\n' );
  1627. X                cclnegate( anyccl );
  1628. X
  1629. X                if ( useecs )
  1630. X                mkeccl( ccltbl + cclmap[anyccl],
  1631. X                    ccllen[anyccl], nextecm,
  1632. X                    ecgroup, csize, csize );
  1633. X
  1634. X                madeany = true;
  1635. X                }
  1636. X
  1637. X            ++rulelen;
  1638. X
  1639. X            $$ = mkstate( -anyccl );
  1640. X            }
  1641. X
  1642. X        |  fullccl
  1643. X            {
  1644. X            if ( ! cclsorted )
  1645. X                /* sort characters for fast searching.  We use a
  1646. X                 * shell sort since this list could be large.
  1647. X                 */
  1648. X                cshell( ccltbl + cclmap[$1], ccllen[$1], true );
  1649. X
  1650. X            if ( useecs )
  1651. X                mkeccl( ccltbl + cclmap[$1], ccllen[$1],
  1652. X                    nextecm, ecgroup, csize, csize );
  1653. X
  1654. X            ++rulelen;
  1655. X
  1656. X            $$ = mkstate( -$1 );
  1657. X            }
  1658. X
  1659. X        |  PREVCCL
  1660. X            {
  1661. X            ++rulelen;
  1662. X
  1663. X            $$ = mkstate( -$1 );
  1664. X            }
  1665. X
  1666. X        |  '"' string '"'
  1667. X            { $$ = $2; }
  1668. X
  1669. X        |  '(' re ')'
  1670. X            { $$ = $2; }
  1671. X
  1672. X        |  CHAR
  1673. X            {
  1674. X            ++rulelen;
  1675. X
  1676. X            if ( caseins && $1 >= 'A' && $1 <= 'Z' )
  1677. X                $1 = clower( $1 );
  1678. X
  1679. X            $$ = mkstate( $1 );
  1680. X            }
  1681. X        ;
  1682. X
  1683. Xfullccl        :  '[' ccl ']'
  1684. X            { $$ = $2; }
  1685. X
  1686. X        |  '[' '^' ccl ']'
  1687. X            {
  1688. X            /* *Sigh* - to be compatible Unix lex, negated ccls
  1689. X             * match newlines
  1690. X             */
  1691. X#ifdef NOTDEF
  1692. X            ccladd( $3, '\n' ); /* negated ccls don't match '\n' */
  1693. X            cclsorted = false; /* because we added the newline */
  1694. X#endif
  1695. X            cclnegate( $3 );
  1696. X            $$ = $3;
  1697. X            }
  1698. X        ;
  1699. X
  1700. Xccl             :  ccl CHAR '-' CHAR
  1701. X                        {
  1702. X            if ( $2 > $4 )
  1703. X                synerr( "negative range in character class" );
  1704. X
  1705. X            else
  1706. X                {
  1707. X                if ( caseins )
  1708. X                {
  1709. X                if ( $2 >= 'A' && $2 <= 'Z' )
  1710. X                    $2 = clower( $2 );
  1711. X                if ( $4 >= 'A' && $4 <= 'Z' )
  1712. X                    $4 = clower( $4 );
  1713. X                }
  1714. X
  1715. X                for ( i = $2; i <= $4; ++i )
  1716. X                    ccladd( $1, i );
  1717. X
  1718. X                /* keep track if this ccl is staying in alphabetical
  1719. X                 * order
  1720. X                 */
  1721. X                cclsorted = cclsorted && ($2 > lastchar);
  1722. X                lastchar = $4;
  1723. X                }
  1724. X
  1725. X            $$ = $1;
  1726. X            }
  1727. X
  1728. X        |  ccl CHAR
  1729. X                {
  1730. X            if ( caseins )
  1731. X                if ( $2 >= 'A' && $2 <= 'Z' )
  1732. X                $2 = clower( $2 );
  1733. X
  1734. X            ccladd( $1, $2 );
  1735. X            cclsorted = cclsorted && ($2 > lastchar);
  1736. X            lastchar = $2;
  1737. X            $$ = $1;
  1738. X            }
  1739. X
  1740. X        |
  1741. X            {
  1742. X            cclsorted = true;
  1743. X            lastchar = 0;
  1744. X            $$ = cclinit();
  1745. X            }
  1746. X        ;
  1747. X
  1748. Xstring        :  string CHAR
  1749. X                        {
  1750. X            if ( caseins )
  1751. X                if ( $2 >= 'A' && $2 <= 'Z' )
  1752. X                $2 = clower( $2 );
  1753. X
  1754. X            ++rulelen;
  1755. X
  1756. X            $$ = link_machines( $1, mkstate( $2 ) );
  1757. X            }
  1758. X
  1759. X        |
  1760. X            { $$ = mkstate( SYM_EPSILON ); }
  1761. X        ;
  1762. X
  1763. X%%
  1764. X
  1765. X
  1766. X/* build_eof_action - build the "<<EOF>>" action for the active start
  1767. X *                    conditions
  1768. X */
  1769. X
  1770. Xvoid build_eof_action()
  1771. X
  1772. X    {
  1773. X    register int i;
  1774. X
  1775. X    for ( i = 1; i <= actvp; ++i )
  1776. X    {
  1777. X    if ( sceof[actvsc[i]] )
  1778. X        format_pinpoint_message(
  1779. X        "multiple <<EOF>> rules for start condition %s",
  1780. X            scname[actvsc[i]] );
  1781. X
  1782. X    else
  1783. X        {
  1784. X        sceof[actvsc[i]] = true;
  1785. X        fprintf( temp_action_file, "case YY_STATE_EOF(%s):\n",
  1786. X             scname[actvsc[i]] );
  1787. X        }
  1788. X    }
  1789. X
  1790. X    line_directive_out( temp_action_file );
  1791. X    }
  1792. X
  1793. X
  1794. X/* synerr - report a syntax error */
  1795. X
  1796. Xvoid synerr( str )
  1797. Xchar str[];
  1798. X
  1799. X    {
  1800. X    syntaxerror = true;
  1801. X    pinpoint_message( str );
  1802. X    }
  1803. X
  1804. X
  1805. X/* format_pinpoint_message - write out a message formatted with one string,
  1806. X *                 pinpointing its location
  1807. X */
  1808. X
  1809. Xvoid format_pinpoint_message( msg, arg )
  1810. Xchar msg[], arg[];
  1811. X
  1812. X    {
  1813. X    char errmsg[MAXLINE];
  1814. X
  1815. X    (void) sprintf( errmsg, msg, arg );
  1816. X    pinpoint_message( errmsg );
  1817. X    }
  1818. X
  1819. X
  1820. X/* pinpoint_message - write out a message, pinpointing its location */
  1821. X
  1822. Xvoid pinpoint_message( str )
  1823. Xchar str[];
  1824. X
  1825. X    {
  1826. X    fprintf( stderr, "\"%s\", line %d: %s\n", infilename, linenum, str );
  1827. X    }
  1828. X
  1829. X
  1830. X/* yyerror - eat up an error message from the parser;
  1831. X *         currently, messages are ignore
  1832. X */
  1833. X
  1834. Xvoid yyerror( msg )
  1835. Xchar msg[];
  1836. X
  1837. X    {
  1838. X    }
  1839. END_OF_FILE
  1840. if test 14546 -ne `wc -c <'parse.y'`; then
  1841.     echo shar: \"'parse.y'\" unpacked with wrong size!
  1842. fi
  1843. # end of 'parse.y'
  1844. fi
  1845. if test -f 'scan.l' -a "${1}" != "-c" ; then 
  1846.   echo shar: Will not clobber existing file \"'scan.l'\"
  1847. else
  1848. echo shar: Extracting \"'scan.l'\" \(12444 characters\)
  1849. sed "s/^X//" >'scan.l' <<'END_OF_FILE'
  1850. X
  1851. X/* scan.l - scanner for flex input */
  1852. X
  1853. X%{
  1854. X/*-
  1855. X * Copyright (c) 1990 The Regents of the University of California.
  1856. X * All rights reserved.
  1857. X *
  1858. X * This code is derived from software contributed to Berkeley by
  1859. X * Vern Paxson.
  1860. X * 
  1861. X * The United States Government has rights in this work pursuant
  1862. X * to contract no. DE-AC03-76SF00098 between the United States
  1863. X * Department of Energy and the University of California.
  1864. X *
  1865. X * Redistribution and use in source and binary forms are permitted provided
  1866. X * that: (1) source distributions retain this entire copyright notice and
  1867. X * comment, and (2) distributions including binaries display the following
  1868. X * acknowledgement:  ``This product includes software developed by the
  1869. X * University of California, Berkeley and its contributors'' in the
  1870. X * documentation or other materials provided with the distribution and in
  1871. X * all advertising materials mentioning features or use of this software.
  1872. X * Neither the name of the University nor the names of its contributors may
  1873. X * be used to endorse or promote products derived from this software without
  1874. X * specific prior written permission.
  1875. X * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
  1876. X * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
  1877. X * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  1878. X */
  1879. X
  1880. X#ifndef lint
  1881. Xstatic char rcsid[] =
  1882. X    "@(#) $Header: WPL:Generators/flex-2.3/RCS/scan.l,v 1.2 90/07/15 01:16:31 loftus Exp $ (LBL)";
  1883. X#endif
  1884. X
  1885. X#undef yywrap
  1886. X
  1887. X#include "flexdef.h"
  1888. X#include "parse.h"
  1889. X
  1890. X#define ACTION_ECHO fprintf( temp_action_file, "%s", yytext )
  1891. X#define MARK_END_OF_PROLOG fprintf( temp_action_file, "%%%% end of prolog\n" );
  1892. X
  1893. X#undef YY_DECL
  1894. X#define YY_DECL \
  1895. X    int flexscan()
  1896. X
  1897. X#define RETURNCHAR \
  1898. X    yylval = yytext[0]; \
  1899. X    return ( CHAR );
  1900. X
  1901. X#define RETURNNAME \
  1902. X    (void) strcpy( nmstr, (char *) yytext ); \
  1903. X    return ( NAME );
  1904. X
  1905. X#define PUT_BACK_STRING(str, start) \
  1906. X    for ( i = strlen( (char *) (str) ) - 1; i >= start; --i ) \
  1907. X        unput((str)[i])
  1908. X
  1909. X#define CHECK_REJECT(str) \
  1910. X    if ( all_upper( str ) ) \
  1911. X        reject = true;
  1912. X
  1913. X#define CHECK_YYMORE(str) \
  1914. X    if ( all_lower( str ) ) \
  1915. X        yymore_used = true;
  1916. X%}
  1917. X
  1918. X%x SECT2 SECT2PROLOG SECT3 CODEBLOCK PICKUPDEF SC CARETISBOL NUM QUOTE
  1919. X%x FIRSTCCL CCL ACTION RECOVER BRACEERROR C_COMMENT ACTION_COMMENT
  1920. X%x ACTION_STRING PERCENT_BRACE_ACTION USED_LIST CODEBLOCK_2 XLATION
  1921. X
  1922. XWS        [ \t\f]+
  1923. XOPTWS        [ \t\f]*
  1924. XNOT_WS        [^ \t\f\n]
  1925. X
  1926. XNAME        [a-z_][a-z_0-9-]*
  1927. XNOT_NAME    [^a-z_\n]+
  1928. X
  1929. XSCNAME        {NAME}
  1930. X
  1931. XESCSEQ        \\([^\n]|[0-9]{1,3}|x[0-9a-f]{1,2})
  1932. X
  1933. X%%
  1934. X    static int bracelevel, didadef;
  1935. X    int i, indented_code, checking_used, new_xlation;
  1936. X    int doing_codeblock = false;
  1937. X    Char nmdef[MAXLINE], myesc();
  1938. X
  1939. X^{WS}            indented_code = true; BEGIN(CODEBLOCK);
  1940. X^#.*\n            ++linenum; /* treat as a comment */
  1941. X^"/*"            ECHO; BEGIN(C_COMMENT);
  1942. X^"%s"{NAME}?        return ( SCDECL );
  1943. X^"%x"{NAME}?        return ( XSCDECL );
  1944. X^"%{".*\n        {
  1945. X            ++linenum;
  1946. X            line_directive_out( stdout );
  1947. X            indented_code = false;
  1948. X            BEGIN(CODEBLOCK);
  1949. X            }
  1950. X
  1951. X{WS}            return ( WHITESPACE );
  1952. X
  1953. X^"%%".*            {
  1954. X            sectnum = 2;
  1955. X            line_directive_out( stdout );
  1956. X            BEGIN(SECT2PROLOG);
  1957. X            return ( SECTEND );
  1958. X            }
  1959. X
  1960. X^"%used"        {
  1961. X    pinpoint_message( "warning - %%used/%%unused have been deprecated" );
  1962. X            checking_used = REALLY_USED; BEGIN(USED_LIST);
  1963. X            }
  1964. X^"%unused"        {
  1965. X            checking_used = REALLY_NOT_USED; BEGIN(USED_LIST);
  1966. X    pinpoint_message( "warning - %%used/%%unused have been deprecated" );
  1967. X            checking_used = REALLY_NOT_USED; BEGIN(USED_LIST);
  1968. X            }
  1969. X
  1970. X
  1971. X^"%"[aeknopt]" ".*\n    {
  1972. X#ifdef NOTDEF
  1973. X            fprintf( stderr,
  1974. X                 "old-style lex command at line %d ignored:\n\t%s",
  1975. X                 linenum, yytext );
  1976. X#endif
  1977. X            ++linenum;
  1978. X            }
  1979. X
  1980. X^"%"[cr]{OPTWS}        /* ignore old lex directive */
  1981. X
  1982. X%t{OPTWS}\n        {
  1983. X            ++linenum;
  1984. X            xlation =
  1985. X                (int *) malloc( sizeof( int ) * (unsigned) csize );
  1986. X
  1987. X            if ( ! xlation )
  1988. X                flexfatal(
  1989. X                "dynamic memory failure building %t table" );
  1990. X
  1991. X            for ( i = 0; i < csize; ++i )
  1992. X                xlation[i] = 0;
  1993. X
  1994. X            num_xlations = 0;
  1995. X
  1996. X            BEGIN(XLATION);
  1997. X            }
  1998. X
  1999. X^"%"[^sxanpekotcru{}]{OPTWS}    synerr( "unrecognized '%' directive" );
  2000. X
  2001. X^{NAME}            {
  2002. X            (void) strcpy( nmstr, (char *) yytext );
  2003. X            didadef = false;
  2004. X            BEGIN(PICKUPDEF);
  2005. X            }
  2006. X
  2007. X{SCNAME}        RETURNNAME;
  2008. X^{OPTWS}\n        ++linenum; /* allows blank lines in section 1 */
  2009. X{OPTWS}\n        ++linenum; return ( '\n' );
  2010. X.            synerr( "illegal character" ); BEGIN(RECOVER);
  2011. X
  2012. X
  2013. X<C_COMMENT>"*/"        ECHO; BEGIN(INITIAL);
  2014. X<C_COMMENT>"*/".*\n    ++linenum; ECHO; BEGIN(INITIAL);
  2015. X<C_COMMENT>[^*\n]+    ECHO;
  2016. X<C_COMMENT>"*"        ECHO;
  2017. X<C_COMMENT>\n        ++linenum; ECHO;
  2018. X
  2019. X
  2020. X<CODEBLOCK>^"%}".*\n    ++linenum; BEGIN(INITIAL);
  2021. X<CODEBLOCK>"reject"    ECHO; CHECK_REJECT(yytext);
  2022. X<CODEBLOCK>"yymore"    ECHO; CHECK_YYMORE(yytext);
  2023. X<CODEBLOCK>{NAME}|{NOT_NAME}|.    ECHO;
  2024. X<CODEBLOCK>\n        {
  2025. X            ++linenum;
  2026. X            ECHO;
  2027. X            if ( indented_code )
  2028. X                BEGIN(INITIAL);
  2029. X            }
  2030. X
  2031. X
  2032. X<PICKUPDEF>{WS}        /* separates name and definition */
  2033. X
  2034. X<PICKUPDEF>{NOT_WS}.*    {
  2035. X            (void) strcpy( (char *) nmdef, (char *) yytext );
  2036. X
  2037. X            for ( i = strlen( (char *) nmdef ) - 1;
  2038. X                  i >= 0 &&
  2039. X                  nmdef[i] == ' ' || nmdef[i] == '\t';
  2040. X                  --i )
  2041. X                ;
  2042. X
  2043. X            nmdef[i + 1] = '\0';
  2044. X
  2045. X                        ndinstal( nmstr, nmdef );
  2046. X            didadef = true;
  2047. X            }
  2048. X
  2049. X<PICKUPDEF>\n        {
  2050. X            if ( ! didadef )
  2051. X                synerr( "incomplete name definition" );
  2052. X            BEGIN(INITIAL);
  2053. X            ++linenum;
  2054. X            }
  2055. X
  2056. X<RECOVER>.*\n        ++linenum; BEGIN(INITIAL); RETURNNAME;
  2057. X
  2058. X
  2059. X<USED_LIST>\n        ++linenum; BEGIN(INITIAL);
  2060. X<USED_LIST>{WS}
  2061. X<USED_LIST>"reject"    {
  2062. X            if ( all_upper( yytext ) )
  2063. X                reject_really_used = checking_used;
  2064. X            else
  2065. X                synerr( "unrecognized %used/%unused construct" );
  2066. X            }
  2067. X<USED_LIST>"yymore"    {
  2068. X            if ( all_lower( yytext ) )
  2069. X                yymore_really_used = checking_used;
  2070. X            else
  2071. X                synerr( "unrecognized %used/%unused construct" );
  2072. X            }
  2073. X<USED_LIST>{NOT_WS}+    synerr( "unrecognized %used/%unused construct" );
  2074. X
  2075. X
  2076. X<XLATION>"%t"{OPTWS}\n    ++linenum; BEGIN(INITIAL);
  2077. X<XLATION>^{OPTWS}[0-9]+    ++num_xlations; new_xlation = true;
  2078. X<XLATION>^.        synerr( "bad row in translation table" );
  2079. X<XLATION>{WS}        /* ignore whitespace */
  2080. X
  2081. X<XLATION>{ESCSEQ}    {
  2082. X            xlation[myesc( yytext )] =
  2083. X                (new_xlation ? num_xlations : -num_xlations);
  2084. X            new_xlation = false;
  2085. X            }
  2086. X<XLATION>.        {
  2087. X            xlation[yytext[0]] =
  2088. X                (new_xlation ? num_xlations : -num_xlations);
  2089. X            new_xlation = false;
  2090. X            }
  2091. X
  2092. X<XLATION>\n        ++linenum;
  2093. X
  2094. X
  2095. X<SECT2PROLOG>.*\n/{NOT_WS}    {
  2096. X            ++linenum;
  2097. X            ACTION_ECHO;
  2098. X            MARK_END_OF_PROLOG;
  2099. X            BEGIN(SECT2);
  2100. X            }
  2101. X
  2102. X<SECT2PROLOG>.*\n    ++linenum; ACTION_ECHO;
  2103. X
  2104. X<SECT2PROLOG><<EOF>>    MARK_END_OF_PROLOG; yyterminate();
  2105. X
  2106. X<SECT2>^{OPTWS}\n    ++linenum; /* allow blank lines in section 2 */
  2107. X
  2108. X<SECT2>^({WS}|"%{")    {
  2109. X            indented_code = (yytext[0] != '%');
  2110. X            doing_codeblock = true;
  2111. X            bracelevel = 1;
  2112. X
  2113. X            if ( indented_code )
  2114. X                ACTION_ECHO;
  2115. X
  2116. X            BEGIN(CODEBLOCK_2);
  2117. X            }
  2118. X
  2119. X<SECT2>"<"        BEGIN(SC); return ( '<' );
  2120. X<SECT2>^"^"        return ( '^' );
  2121. X<SECT2>\"        BEGIN(QUOTE); return ( '"' );
  2122. X<SECT2>"{"/[0-9]        BEGIN(NUM); return ( '{' );
  2123. X<SECT2>"{"[^0-9\n][^}\n]*    BEGIN(BRACEERROR);
  2124. X<SECT2>"$"/[ \t\n]    return ( '$' );
  2125. X
  2126. X<SECT2>{WS}"%{"        {
  2127. X            bracelevel = 1;
  2128. X            BEGIN(PERCENT_BRACE_ACTION);
  2129. X            return ( '\n' );
  2130. X            }
  2131. X<SECT2>{WS}"|".*\n    continued_action = true; ++linenum; return ( '\n' );
  2132. X
  2133. X<SECT2>{WS}        {
  2134. X            /* this rule is separate from the one below because
  2135. X             * otherwise we get variable trailing context, so
  2136. X             * we can't build the scanner using -{f,F}
  2137. X             */
  2138. X            bracelevel = 0;
  2139. X            continued_action = false;
  2140. X            BEGIN(ACTION);
  2141. X            return ( '\n' );
  2142. X            }
  2143. X
  2144. X<SECT2>{OPTWS}/\n    {
  2145. X            bracelevel = 0;
  2146. X            continued_action = false;
  2147. X            BEGIN(ACTION);
  2148. X            return ( '\n' );
  2149. X            }
  2150. X
  2151. X<SECT2>^{OPTWS}\n    ++linenum; return ( '\n' );
  2152. X
  2153. X<SECT2>"<<EOF>>"    return ( EOF_OP );
  2154. X
  2155. X<SECT2>^"%%".*        {
  2156. X            sectnum = 3;
  2157. X            BEGIN(SECT3);
  2158. X            return ( EOF ); /* to stop the parser */
  2159. X            }
  2160. X
  2161. X<SECT2>"["([^\\\]\n]|{ESCSEQ})+"]"    {
  2162. X            int cclval;
  2163. X
  2164. X            (void) strcpy( nmstr, (char *) yytext );
  2165. X
  2166. X            /* check to see if we've already encountered this ccl */
  2167. X            if ( (cclval = ccllookup( (Char *) nmstr )) )
  2168. X                {
  2169. X                yylval = cclval;
  2170. X                ++cclreuse;
  2171. X                return ( PREVCCL );
  2172. X                }
  2173. X            else
  2174. X                {
  2175. X                /* we fudge a bit.  We know that this ccl will
  2176. X                 * soon be numbered as lastccl + 1 by cclinit
  2177. X                 */
  2178. X                cclinstal( (Char *) nmstr, lastccl + 1 );
  2179. X
  2180. X                /* push back everything but the leading bracket
  2181. X                 * so the ccl can be rescanned
  2182. X                 */
  2183. X                PUT_BACK_STRING((Char *) nmstr, 1);
  2184. X
  2185. X                BEGIN(FIRSTCCL);
  2186. X                return ( '[' );
  2187. X                }
  2188. X            }
  2189. X
  2190. X<SECT2>"{"{NAME}"}"    {
  2191. X            register Char *nmdefptr;
  2192. X            Char *ndlookup();
  2193. X
  2194. X            (void) strcpy( nmstr, (char *) yytext );
  2195. X            nmstr[yyleng - 1] = '\0';  /* chop trailing brace */
  2196. X
  2197. X            /* lookup from "nmstr + 1" to chop leading brace */
  2198. X            if ( ! (nmdefptr = ndlookup( nmstr + 1 )) )
  2199. X                synerr( "undefined {name}" );
  2200. X
  2201. X            else
  2202. X                { /* push back name surrounded by ()'s */
  2203. X                unput(')');
  2204. X                PUT_BACK_STRING(nmdefptr, 0);
  2205. X                unput('(');
  2206. X                }
  2207. X            }
  2208. X
  2209. X<SECT2>[/|*+?.()]    return ( (int) yytext[0] );
  2210. X<SECT2>.        RETURNCHAR;
  2211. X<SECT2>\n        ++linenum; return ( '\n' );
  2212. X
  2213. X
  2214. X<SC>","            return ( ',' );
  2215. X<SC>">"            BEGIN(SECT2); return ( '>' );
  2216. X<SC>">"/"^"        BEGIN(CARETISBOL); return ( '>' );
  2217. X<SC>{SCNAME}        RETURNNAME;
  2218. X<SC>.            synerr( "bad start condition name" );
  2219. X
  2220. X<CARETISBOL>"^"        BEGIN(SECT2); return ( '^' );
  2221. X
  2222. X
  2223. X<QUOTE>[^"\n]        RETURNCHAR;
  2224. X<QUOTE>\"        BEGIN(SECT2); return ( '"' );
  2225. X
  2226. X<QUOTE>\n        {
  2227. X            synerr( "missing quote" );
  2228. X            BEGIN(SECT2);
  2229. X            ++linenum;
  2230. X            return ( '"' );
  2231. X            }
  2232. X
  2233. X
  2234. X<FIRSTCCL>"^"/[^-\n]    BEGIN(CCL); return ( '^' );
  2235. X<FIRSTCCL>"^"/-        return ( '^' );
  2236. X<FIRSTCCL>-        BEGIN(CCL); yylval = '-'; return ( CHAR );
  2237. X<FIRSTCCL>.        BEGIN(CCL); RETURNCHAR;
  2238. X
  2239. X<CCL>-/[^\]\n]        return ( '-' );
  2240. X<CCL>[^\]\n]        RETURNCHAR;
  2241. X<CCL>"]"        BEGIN(SECT2); return ( ']' );
  2242. X
  2243. X
  2244. X<NUM>[0-9]+        {
  2245. X            yylval = myctoi( yytext );
  2246. X            return ( NUMBER );
  2247. X            }
  2248. X
  2249. X<NUM>","            return ( ',' );
  2250. X<NUM>"}"            BEGIN(SECT2); return ( '}' );
  2251. X
  2252. X<NUM>.            {
  2253. X            synerr( "bad character inside {}'s" );
  2254. X            BEGIN(SECT2);
  2255. X            return ( '}' );
  2256. X            }
  2257. X
  2258. X<NUM>\n            {
  2259. X            synerr( "missing }" );
  2260. X            BEGIN(SECT2);
  2261. X            ++linenum;
  2262. X            return ( '}' );
  2263. X            }
  2264. X
  2265. X
  2266. X<BRACEERROR>"}"        synerr( "bad name in {}'s" ); BEGIN(SECT2);
  2267. X<BRACEERROR>\n        synerr( "missing }" ); ++linenum; BEGIN(SECT2);
  2268. X
  2269. X
  2270. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>{OPTWS}"%}".*        bracelevel = 0;
  2271. X<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"reject"    {
  2272. X            ACTION_ECHO;
  2273. X            CHECK_REJECT(yytext);
  2274. X            }
  2275. X<PERCENT_BRACE_ACTION,CODEBLOCK_2,ACTION>"yymore"    {
  2276. X            ACTION_ECHO;
  2277. X            CHECK_YYMORE(yytext);
  2278. X            }
  2279. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>{NAME}|{NOT_NAME}|.    ACTION_ECHO;
  2280. X<PERCENT_BRACE_ACTION,CODEBLOCK_2>\n            {
  2281. X            ++linenum;
  2282. X            ACTION_ECHO;
  2283. X            if ( bracelevel == 0 ||
  2284. X                 (doing_codeblock && indented_code) )
  2285. X                {
  2286. X                if ( ! doing_codeblock )
  2287. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2288. X                
  2289. X                doing_codeblock = false;
  2290. X                BEGIN(SECT2);
  2291. X                }
  2292. X            }
  2293. X
  2294. X
  2295. X    /* Reject and YYmore() are checked for above, in PERCENT_BRACE_ACTION */
  2296. X<ACTION>"{"        ACTION_ECHO; ++bracelevel;
  2297. X<ACTION>"}"        ACTION_ECHO; --bracelevel;
  2298. X<ACTION>[^a-z_{}"'/\n]+    ACTION_ECHO;
  2299. X<ACTION>{NAME}        ACTION_ECHO;
  2300. X<ACTION>"/*"        ACTION_ECHO; BEGIN(ACTION_COMMENT);
  2301. X<ACTION>"'"([^'\\\n]|\\.)*"'"    ACTION_ECHO; /* character constant */
  2302. X<ACTION>\"        ACTION_ECHO; BEGIN(ACTION_STRING);
  2303. X<ACTION>\n        {
  2304. X            ++linenum;
  2305. X            ACTION_ECHO;
  2306. X            if ( bracelevel == 0 )
  2307. X                {
  2308. X                fputs( "\tYY_BREAK\n", temp_action_file );
  2309. X                BEGIN(SECT2);
  2310. X                }
  2311. X            }
  2312. X<ACTION>.        ACTION_ECHO;
  2313. X
  2314. X<ACTION_COMMENT>"*/"    ACTION_ECHO; BEGIN(ACTION);
  2315. X<ACTION_COMMENT>[^*\n]+    ACTION_ECHO;
  2316. X<ACTION_COMMENT>"*"    ACTION_ECHO;
  2317. X<ACTION_COMMENT>\n    ++linenum; ACTION_ECHO;
  2318. X<ACTION_COMMENT>.    ACTION_ECHO;
  2319. X
  2320. X<ACTION_STRING>[^"\\\n]+    ACTION_ECHO;
  2321. X<ACTION_STRING>\\.    ACTION_ECHO;
  2322. X<ACTION_STRING>\n    ++linenum; ACTION_ECHO;
  2323. X<ACTION_STRING>\"    ACTION_ECHO; BEGIN(ACTION);
  2324. X<ACTION_STRING>.    ACTION_ECHO;
  2325. X
  2326. X<ACTION,ACTION_COMMENT,ACTION_STRING><<EOF>>    {
  2327. X            synerr( "EOF encountered inside an action" );
  2328. X            yyterminate();
  2329. X            }
  2330. X
  2331. X
  2332. X<SECT2,QUOTE,CCL>{ESCSEQ}    {
  2333. X            yylval = myesc( yytext );
  2334. X            return ( CHAR );
  2335. X            }
  2336. X
  2337. X<FIRSTCCL>{ESCSEQ}    {
  2338. X            yylval = myesc( yytext );
  2339. X            BEGIN(CCL);
  2340. X            return ( CHAR );
  2341. X            }
  2342. X
  2343. X
  2344. X<SECT3>.*(\n?)        ECHO;
  2345. X%%
  2346. X
  2347. X
  2348. Xint yywrap()
  2349. X
  2350. X    {
  2351. X    if ( --num_input_files > 0 )
  2352. X    {
  2353. X    set_input_file( *++input_files );
  2354. X    return ( 0 );
  2355. X    }
  2356. X
  2357. X    else
  2358. X    return ( 1 );
  2359. X    }
  2360. X
  2361. X
  2362. X/* set_input_file - open the given file (if NULL, stdin) for scanning */
  2363. X
  2364. Xvoid set_input_file( file )
  2365. Xchar *file;
  2366. X
  2367. X    {
  2368. X    if ( file )
  2369. X    {
  2370. X    infilename = file;
  2371. X    yyin = fopen( infilename, "r" );
  2372. X
  2373. X    if ( yyin == NULL )
  2374. X        lerrsf( "can't open %s", file );
  2375. X    }
  2376. X
  2377. X    else
  2378. X    {
  2379. X    yyin = stdin;
  2380. X    infilename = "<stdin>";
  2381. X    }
  2382. X    }
  2383. END_OF_FILE
  2384. if test 12444 -ne `wc -c <'scan.l'`; then
  2385.     echo shar: \"'scan.l'\" unpacked with wrong size!
  2386. fi
  2387. # end of 'scan.l'
  2388. fi
  2389. echo shar: End of archive 2 \(of 13\).
  2390. cp /dev/null ark2isdone
  2391. MISSING=""
  2392. for I in 1 2 3 4 5 6 7 8 9 10 11 12 13 ; do
  2393.     if test ! -f ark${I}isdone ; then
  2394.     MISSING="${MISSING} ${I}"
  2395.     fi
  2396. done
  2397. if test "${MISSING}" = "" ; then
  2398.     echo You have unpacked all 13 archives.
  2399.     rm -f ark[1-9]isdone ark[1-9][0-9]isdone
  2400. else
  2401.     echo You still need to unpack the following archives:
  2402.     echo "        " ${MISSING}
  2403. fi
  2404. ##  End of shell archive.
  2405. exit 0
  2406. -- 
  2407. Mail submissions (sources or binaries) to <amiga@uunet.uu.net>.
  2408. Mail comments to the moderator at <amiga-request@uunet.uu.net>.
  2409. Post requests for sources, and general discussion to comp.sys.amiga.
  2410.